<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    public function _initView()
    {
        Zend_Session::start();

        $this->bootstrap('layout');
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=utf-8');

        // CSS

        $view->headLink()->appendStylesheet($view->baseUrl() . '/bootstrap/css/bootstrap.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/bootstrap/css/bootstrap-responsive.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/js/pnotify/css/jquery.pnotify.default.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/js/pnotify/css/jquery.pnotify.default.icons.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/css/base.css', 'screen');
        // JS
        $view->headScript()->appendFile('http://code.jquery.com/jquery-1.8.3.min.js');
        $view->headScript()->appendFile($view->baseUrl() . '/bootstrap/js/bootstrap.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/pnotify/js/jquery.pnotify.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/base.js');
        $view->headScript()->appendFile('http://html5shiv.googlecode.com/svn/trunk/html5.js');
    }

    protected function _initNavigation()
    {
        $config = array(
            Zend_Navigation_Page::factory(
                array(
                    'label' => 'Финансы',
                    'uri'   => '/money',
                )
            ),
            Zend_Navigation_Page::factory(array(
                    'label' => 'Покупки',
                    'uri'   => '/buy',
//                    'pages' =>
                )
            ),
            Zend_Navigation_Page::factory(array(
                    'label' => 'Планы',
                    'uri'   => '/idea',
//                    'pages' =>
                )
            ),
            Zend_Navigation_Page::factory(array(
                    'label' => 'Учеба',
                    'uri'   => '/study',
                )
            ),
            Zend_Navigation_Page::factory(array(
                    'label' => 'Путешествия',
                    'uri'   => '/travel',
                )
            ),
        );

        $container = new Zend_Navigation($config);
        Zend_Registry::getInstance()->set('Zend_Navigation', $container);
    }

    protected function _initRoute()
    {
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');
        $router = $front->getRouter();

        $route = new Zend_Controller_Router_Route(
            'calendar/',
            array(
                'controller' => 'idea',
                'action'     => 'calendar',
            )
        );

        $router->addRoute('calendar', $route);

        $route = new Zend_Controller_Router_Route(
            'notes/',
            array(
                'controller' => 'index',
                'action'     => 'notes',
            )
        );

        $router->addRoute('notes', $route);
    }

    protected function _initZFDebug()
    {
        $prf = new Zend_Session_Namespace('prf');

        if ($prf->val !== 1) {
            return false;
        }

        $this->bootstrap('db');
        $dbAdapter = $this->getResource('db');

        // Setup autoloader with namespace
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('ZFDebug');

        $options = array(
            'plugins' => array('Variables',
                'Database' => array('adapter' => $dbAdapter),
                'Memory',
                'Time',
//                'Registry',
//                'Cache' => array('backend' => $cache->getBackend()),
//                'Exception'
            )
        );


        // Ensure the front controller is initialized
        $this->bootstrap('FrontController');

        // Retrieve the front controller from the bootstrap registry
        $front = $this->getResource('FrontController');

        // Only enable zfdebug if options have been specified for it
        if ($this->hasOption('zfdebug')) {
            // Create ZFDebug instance
            $debug = new ZFDebug_Controller_Plugin_Debug($options);

            // Register ZFDebug with the front controller
            $front->registerPlugin($debug);
        }

        return true;
    }

    //TODO добавить во все вьюшки экранирование $this->escape()
    //TODO весь русский текст обернуть в translate
}

